package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
@Api(tags="测试类的相关接口")
public class TestController {
    @ApiOperation("测试接口1,显示test success")
    @GetMapping("/test1")
    public String test(){
        return "test success";
    }
    @ApiOperation("测试接口2,显示抛出的异常信息")
    @GetMapping("/testException")
    public AppResult testException() throws Exception{
        throw new Exception("这是一个测试Exception...");
    }
    @ApiOperation("测试接口3,显示自定义的异常抛出信息")
    @RequestMapping("/appException")
    public AppResult testApplicationException() throws Exception{
        throw new Exception("这是一个ApplicationException...");
    }
    @ApiOperation("测试接口4,按照传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByname(@ApiParam(value ="姓名")@RequestParam("name")@NonNull String name){
        return AppResult.success("hello:"+name);
    }
    @ApiOperation("API参数测试")
    @RequestMapping("/testApi")
    public AppResult testApiParams(String first, @RequestBody User user){
        return AppResult.success(first);
    }
}
